FILES_FETCH = adder.vhdl flopr.vhdl mux2.vhdl imem.vhd fetch.vhdl
FILES_DECODE = regfile.vhdl signext.vhdl controller.vhdl decode.vhdl
FILES_EXECUTE = mux2.vhdl sl2.vhdl alu.vhdl adder.vhdl execute.vhdl
FILES_MEMORY = dmem.vhd memory.vhdl
FILES_WRITE_BACK = mux2.vhdl writeback.vhdl
FILES_VHDL = *.vhdl *.vhd
ARCHITECTURE = mips
ARCHITECTURE_TEST = mips_test_bench

COMPILER = ghdl
EXECUTER = gtkwave

EXTRA_FLAG = --ieee=synopsys -fexplicit
LAB_FLAGS_A = -Wc,-m32 -Wa,--32
LAB_FLAGS_E = -Wa,--32 -Wl,-m32

all:
	$(COMPILER) -a $(EXTRA_FLAG) $(FILES_VHDL)
	$(COMPILER) -e $(EXTRA_FLAG) $(ARCHITECTURE_TEST)
	$(COMPILER) -r $(ARCHITECTURE_TEST) --stop-time=220ns --vcd=$(ARCHITECTURE).vcd
	$(EXECUTER) $(ARCHITECTURE).vcd

lab:
	$(COMPILER) -a $(EXTRA_FLAG) $(LAB_FLAGS_A) $(FILES_VHDL)
	$(COMPILER) -e $(EXTRA_FLAG) $(LAB_FLAGS_E) $(ARCHITECTURE_TEST)
	$(COMPILER) -r $(ARCHITECTURE_TEST) --stop-time=220ns --vcd=$(ARCHITECTURE).vcd
	$(EXECUTER) $(ARCHITECTURE).vcd

fetch:
	$(COMPILER) -a $(EXTRA_FLAG) $(FILES_FETCH)
#	$(COMPILER) -e $(EXTRA_FLAG) fetch_test_bench
#	$(COMPILER) -r fetch_test_bench --stop-time=30ns --vcd=fetch.vcd
#	$(EXECUTER) fetch.vcd
	
decode:
	$(COMPILER) -a $(EXTRA_FLAG) $(FILES_DECODE)
#	$(COMPILER) -e $(EXTRA_FLAG) decode_test_bench
#	$(COMPILER) -r decode_test_bench --stop-time=30ns --vcd=decode.vcd
#	$(EXECUTER) decode.vcd

execute:
	$(COMPILER) -a $(EXTRA_FLAG) $(FILES_EXECUTE)
#	$(COMPILER) -e $(EXTRA_FLAG) fetch_test_bench
#	$(COMPILER) -r execute_test_bench --stop-time=30ns --vcd=execute.vcd
#	$(EXECUTER) execute.vcd

memory:
	$(COMPILER) -a $(EXTRA_FLAG) $(FILES_MEMORY)
#	$(COMPILER) -e $(EXTRA_FLAG) memory_test_bench
#	$(COMPILER) -r memory_test_bench --stop-time=30ns --vcd=memory.vcd
#	$(EXECUTER) memory.vcd

writeback:
	$(COMPILER) -a $(EXTRA_FLAG) $(FILES_WRITEBACK)
#	$(COMPILER) -e $(EXTRA_FLAG) writeback_test_bench
#	$(COMPILER) -r writeback_test_bench --stop-time=30ns --vcd=writeback.vcd
#	$(EXECUTER) writeback.vcd

clean:
	rm *.o *.cf $(ARCHITECTURE_TEST) *.vcd
